package com.hengxinguotong.baselibrary.dialog;

import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;

import com.hengxinguotong.baselibrary.R;

/**
 * Created by hjz on 2018/4/10.
 */

public class MediaDialog extends AlertDialog
{
    private SelectCallback selectCallback;

    public MediaDialog(@NonNull Context context, SelectCallback selectCallback)
    {
        super(context, R.style.dialog_default_theme);
        this.selectCallback = selectCallback;
    }

    public MediaDialog(@NonNull Context context, int themeResId)
    {
        super(context, themeResId);
    }

    protected MediaDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener)
    {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_media);
        LinearLayout dialogCamera = findViewById(R.id.dialog_camera);
        dialogCamera.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {
                dismiss();
                selectCallback.onCamera();
            }
        });
        final LinearLayout dialogAlbum = findViewById(R.id.dialog_album);
        dialogAlbum.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {
                dismiss();
                selectCallback.onAlbum();
            }
        });
        setCancelable(true);
        setCanceledOnTouchOutside(true);
    }

    public interface SelectCallback
    {
        void onCamera();

        void onAlbum();
    }
}
